﻿package view.selectView.control
{
    import com.greensock.*;
    import flash.geom.*;
    import uiresource.*;

    public class BossBlood extends Object
    {
        private var _bloodBar:BloodBarUI;
        public var bloodValue:int;
        public var alphaValue:int;
        public var maxValue:int = 0;
        private var _bloodRect:Rectangle;
        private var _alphaRect:Rectangle;
        private var _maxWidth:int = 0;
        private var _timeline:TimelineLite;
        private var _tubes:int = 4;
        private var _bloodLimit:Number = 100;
        private var _sorts:Array;

        public function BossBlood(param1:BloodBarUI)
        {
            this._sorts = ["png.common.red", "png.common.boss01", "png.common.boss02", "png.common.boss03", "png.common.boss04"];
            this._bloodBar = param1;
            this._bloodRect = new Rectangle(0, 0, 0, 10);
            this._alphaRect = new Rectangle(0, 0, 0, 10);
            this._maxWidth = this._bloodBar.bloodBg.width;
            return;
        }// end function

        public function checkBlood() : void
        {
            var _loc_1:* = this.bloodValue / this._bloodLimit;
            var _loc_2:* = int(_loc_1);
            var _loc_3:* = (Math.ceil(_loc_1) - 1) % 5;
            this._bloodBar.bloodRun.url = this._sorts[_loc_3];
            if (_loc_2 != _loc_1)
            {
                if (_loc_3 == 0)
                {
                    this._bloodBar.bloodBg.visible = false;
                }
                else
                {
                    this._bloodBar.bloodBg.visible = true;
                    this._bloodBar.bloodBg.url = this._sorts[(_loc_3 - 1) < 0 ? (4) : ((_loc_3 - 1))];
                }
            }
            _loc_1 = this.alphaValue / this._bloodLimit;
            _loc_2 = int(_loc_1);
            var _loc_4:* = (Math.ceil(_loc_1) - 1) % 5;
            this._bloodBar.alphaRun.url = this._sorts[_loc_4];
            if (_loc_2 != _loc_1)
            {
                if (_loc_4 == _loc_3)
                {
                    this._bloodBar.alphaBg.visible = false;
                }
                else if (_loc_4 == 0)
                {
                    this._bloodBar.alphaBg.visible = false;
                }
                else
                {
                    this._bloodBar.alphaBg.visible = true;
                    this._bloodBar.alphaBg.url = this._sorts[(_loc_4 - 1) < 0 ? (4) : ((_loc_4 - 1))];
                }
            }
            return;
        }// end function

        public function setBlood(param1:int, param2:int, param3:Boolean) : void
        {
            if (param3)
            {
                var _loc_5:* = param1;
                this.alphaValue = param1;
                this.bloodValue = _loc_5;
                this.maxValue = param2;
                this._bloodLimit = (param2 + 1) / this._tubes;
                this._bloodBar.alphaBg.visible = false;
                this.updateAlpha();
                this.updateBlood();
            }
            else
            {
                this.checkBlood();
            }
            var _loc_4:* = param1 < 0 ? (0) : (param1);
            if (this.bloodValue == 0)
            {
                return;
            }
            if (this._timeline)
            {
                this._timeline.kill();
            }
            this._timeline = new TimelineLite();
            this._timeline.insert(new TweenLite(this, 0.2, {bloodValue:_loc_4, onUpdate:this.updateBlood}));
            this._timeline.insert(new TweenLite(this, 2, {alphaValue:_loc_4, onUpdate:this.updateAlpha}));
            this._timeline.play();
            return;
        }// end function

        private function updateBlood() : void
        {
            this._bloodRect.width = this.bloodValue % this._bloodLimit / this._bloodLimit * this._maxWidth;
            this._bloodBar.bloodRun.scrollRect = this._bloodRect;
            this.checkBlood();
            return;
        }// end function

        private function updateAlpha() : void
        {
            this._alphaRect.width = this.alphaValue % this._bloodLimit / this._bloodLimit * this._maxWidth;
            this._bloodBar.alphaRun.scrollRect = this._alphaRect;
            this.checkBlood();
            return;
        }// end function

        public function set tubes(param1:int) : void
        {
            this._tubes = param1;
            return;
        }// end function

    }
}
